package com.itheima.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @Author 王加鑫
 * @Date 2021/5/25 11:06
 * @Version 1.0
 */
public class 接收端 {

    public static void main(String[] args) throws IOException {
        //创建Socket对象(类似快递公司的性质,拆装快递的意思)
        DatagramSocket socket = new DatagramSocket(10000);
        //创建字节数组,表示要读取1024字节的字节数组内容
        byte[] bytes = new byte[1024];
        while (true){
            DatagramPacket packet = new DatagramPacket(bytes,0,bytes.length);
            //获取快递包裹里面的内容
            socket.receive(packet);
            //获取内容的个数
            int i = packet.getLength();
            System.out.println(new String(bytes,0,i));
        }

    }
}
